package com.mc.code.sysService.Impl;

import com.mc.code.entity.sys.SysUser;
import com.mc.code.mapper.SysUserMapper;
import com.mc.code.sysService.SysUserService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class SysUserServiceImpl implements SysUserService {
    @Autowired
    private SysUserMapper sysUserMapper;


    @Override
    public String findMaxId() {
        int adminNo = Integer.parseInt(sysUserMapper.findMaxId()) + 1;
        return String.valueOf(adminNo);
    }

    //根据条件查找
    @Override
    public List<SysUser> findUserByCondition(String adminNo,String adminName,String state,int currentPage, int pageCount) {
        return sysUserMapper.findUserByCondition(adminNo,adminName,state,(currentPage - 1) * pageCount,pageCount);
    }

    @Override
    public SysUser findUserById(int id) {
        return sysUserMapper.findUserById(id);
    }

    @Override
    public SysUser findUserByNo(String adminNo) {
        return sysUserMapper.findUserByNo(adminNo);
    }

    @Override
    public SysUser findUserByName(String adminName) {
        return sysUserMapper.findUserByName(adminName);
    }

    @Override
    public int save(SysUser sysUser) {
        return sysUserMapper.save(sysUser);
    }

    @Override
    public int updateUser(SysUser sysUser) {
        return sysUserMapper.updateUser(sysUser);
    }

    @Override
    public int updateUserById(SysUser sysUser) {
        return sysUserMapper.updateUserById(sysUser);
    }

    @Override
    public int enableById(int id) {
        return sysUserMapper.enableById(id);
    }

    @Override
    public int disableById(int id) {
        return sysUserMapper.disableById(id);
    }


    @Override
    public int deleteUser(int id) {
        return sysUserMapper.deleteUser(id);
    }

    @Override
    public int findIdByAdminNo(String adminNo) {
        return sysUserMapper.findIdByAdminNo(adminNo);
    }

    @Override
    public int saveToUserRole(int userId,int roleId) {
        return sysUserMapper.saveToUserRole(userId,roleId);
    }

    @Override
    public int updateRole(int userId, int roleId) {
        return sysUserMapper.updateRole(userId,roleId);
    }

    //分页，获得总数
    @Override
    public int getTotalPage(int pageCount,String adminNo, String adminName, String state) {
        Integer total =sysUserMapper.getTotalPage(adminNo,adminName,state);
        return (total - 1) / pageCount + 1;
    }
}
